import { QueryClient, QueryClientProvider } from "@tanstack/solid-query";
/* @refresh reload */
import { render } from "solid-js/web";
import "./index.css";
import { type JSX, onMount } from "solid-js";
import Routes from "@/routes";
import useAuthStore from "./store/auth";

const queryClient = new QueryClient();

function App(props: { children: JSX.Element }) {
  const { load } = useAuthStore();

  onMount(() => {
    load();
  });

  return <>{props.children}</>;
}

const root = document.getElementById("root");
if (root) {
  render(
    () => (
      <QueryClientProvider client={queryClient}>
        <App>
          <Routes />
        </App>
      </QueryClientProvider>
    ),
    root,
  );
}
